package com.xique.park.controller.auto;

import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.ParkDeviceSub;
import com.xique.park.service.service.IParkDeviceSubService;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.page.TableDataInfo;

/**
 * 挂在主摄像机下的其他设备Controller
 * 
 * @author xique
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/deviceSub")
public class ParkDeviceSubController extends BaseController
{
    @Autowired
    private IParkDeviceSubService parkDeviceSubService;

    /**
     * 查询挂在主摄像机下的其他设备列表
     */
    @PreAuthorize(hasPermi = "park:sub:list")
    @GetMapping("/list")
    public TableDataInfo list(ParkDeviceSub parkDeviceSub)
    {
        startPage();
        List<ParkDeviceSub> list = parkDeviceSubService.selectParkDeviceSubList(parkDeviceSub);
        return getDataTable(list);
    }

    /**
     * 导出挂在主摄像机下的其他设备列表
     */
    @PreAuthorize(hasPermi = "park:sub:export")
    @Log(title = "挂在主摄像机下的其他设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkDeviceSub parkDeviceSub) throws IOException
    {
        List<ParkDeviceSub> list = parkDeviceSubService.selectParkDeviceSubList(parkDeviceSub);
        ExcelUtil<ParkDeviceSub> util = new ExcelUtil<ParkDeviceSub>(ParkDeviceSub.class);
        util.exportExcel(response, list, "挂在主摄像机下的其他设备数据");
    }

    /**
     * 获取挂在主摄像机下的其他设备详细信息
     */
    @PreAuthorize(hasPermi = "park:sub:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(parkDeviceSubService.selectParkDeviceSubById(id));
    }

    /**
     * 新增挂在主摄像机下的其他设备
     */
    @PreAuthorize(hasPermi = "park:sub:add")
    @Log(title = "挂在主摄像机下的其他设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkDeviceSub parkDeviceSub)
    {
        return toAjax(parkDeviceSubService.insertParkDeviceSub(parkDeviceSub));
    }

    /**
     * 修改挂在主摄像机下的其他设备
     */
    @PreAuthorize(hasPermi = "park:sub:edit")
    @Log(title = "挂在主摄像机下的其他设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkDeviceSub parkDeviceSub)
    {
        return toAjax(parkDeviceSubService.updateParkDeviceSub(parkDeviceSub));
    }

    /**
     * 删除挂在主摄像机下的其他设备
     */
    @PreAuthorize(hasPermi = "park:sub:remove")
    @Log(title = "挂在主摄像机下的其他设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        List<Long> idList = Arrays.asList(ids);
        return toAjax(parkDeviceSubService.deleteParkDeviceSubByIds(idList));
    }
}
